<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_link extends Admin_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('link_mdl');
		$this->uid = $this->user_login->is_logged_in() ? $this->user_login->get_user_id() : 0;
	}

	public function index()
	{
		$this->lists();
	}

	public function lists()
	{
		$page = max(1, intval($this->input->post('pageNum')));
		$limit = 18; //每页显示数
		$offset = ($page - 1) * $limit;

		//分页
		$data['totalCount'] = 100;
		$data['numPerPage'] = $limit;
		$data['currentPage'] = $page;

		$data['lists'] = $this->link_mdl->get(array(), $offset, $limit)->result_array();

		
		$this->load->view('link', $data);
	}

	public function adds($cid = '')
	{
		if ($this->input->post('submit') == 'ok')
		{
			$arr = array(
				'title' => $this->input->post('title'),
				'url' => $this->input->post('url'),
				'order' => $this->input->post('order'),
				'desc' => $this->input->post('desc'),
				'addtime' => time(),
			);
			$result = $this->link_mdl->insert($arr);
			$this->_jui_message('操作成功');
		}
		else
		{
			$data['info'] = 0;
			$this->load->view('link_edit', $data);
		}
	}
	public function edits($id = '')
	{
		if(empty($id) || !is_numeric($id))
		{
			show_error('失败：参数有误');
			exit();
		}

		if ($this->input->post('submit') == 'ok')
		{
			$arr = array(
				'title' => $this->input->post('title'),
				'url' => $this->input->post('url'),
				'order' => $this->input->post('order'),
				'desc' => $this->input->post('desc'),
			);

			$result = $this->link_mdl->update($arr, array('id'=>$id));
			$this->_jui_message('操作成功');
		}
		else
		{
			$data['info'] = $this->link_mdl->get_by(array('id'=>$id));
			/** 不存在? */
			if(!$data['info'])
			{
				redirect('admin_link');
				exit();
			}

			$this->load->view('link_edit', $data);
		}

	}
	
	public function delete($id = '')
	{
		$result = $this->link_mdl->delete(array('id'=>$id));
		$this->_jui_message('删除成功');
	}


}

/* End of file admin_article.php */
/* Location: ./application/controllers/manage/admin_article.php */